<?php
header("Access-Control-Allow-Methods: GET, POST, PUT, DELETE");
header("Access-Control-Allow-Headers: Content-Type");
$root = preg_replace("/^(.*(yunshop|shante)).*$/Uisx", "\\1", getcwd());
require_once("{$root}/myzhuaqu.php");
require_once("{$root}/vendor/autoload.php");
include("{$_SERVER['DOCUMENT_ROOT']}/class/Sku.php");

if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
    http_response_code(200);
    exit();
}
$sku=new Sku();
$raw_post_data = file_get_contents('php://input');
$data_post = json_decode($raw_post_data, true);
if($data_post["category_shante"]!=""){
    $sku->shoptype("shante");
    $mapId=$sku->clMapCategory($data_post["category_shante"]);
    execute("update jipu.jipu_item_category_map set category_1='{$data_post["category_shante"]}', category_2='{$data_post["category_douyin"]}', category_3='{$data_post["category_weixin"]}', category_4='{$data_post["category_shopee"]}' where id={$mapId}");
    $sku->clMapOtherShoptypeCategory($mapId);
}elseif($data_post["category_douyin"]!=""){
    $sku->shoptype("douyin");
    $mapId=$sku->clMapCategory($data_post["category_douyin"]);
    execute("update jipu.jipu_item_category_map set category_1='{$data_post["category_shante"]}', category_2='{$data_post["category_douyin"]}', category_3='{$data_post["category_weixin"]}', category_4='{$data_post["category_shopee"]}' where id={$mapId}");
    $sku->clMapOtherShoptypeCategory($mapId);
}elseif($data_post["category_weixin"]!=""){
    $sku->shoptype("weixin");
    $mapId=$sku->clMapCategory($data_post["category_weixin"]);
    execute("update jipu.jipu_item_category_map set category_1='{$data_post["category_shante"]}', category_2='{$data_post["category_douyin"]}', category_3='{$data_post["category_weixin"]}', category_4='{$data_post["category_shopee"]}' where id={$mapId}");
    $sku->clMapOtherShoptypeCategory($mapId);
}elseif($data_post["category_shopee"]!=""){
    $sku->shoptype("shopee");
    $mapId=$sku->clMapCategory($data_post["category_shopee"]);
    execute("update jipu.jipu_item_category_map set category_1='{$data_post["category_shante"]}', category_2='{$data_post["category_douyin"]}', category_3='{$data_post["category_weixin"]}', category_4='{$data_post["category_shopee"]}' where id={$mapId}");
    $sku->clMapOtherShoptypeCategory($mapId);
}
$result=array();
$result['code']=1;
$result['message']="更新成功！";
$result['data']=array(
  'mapId'=>$mapId
);
echo json_encode($result);

